from util import Packable, strlist, lookup_table, bitflags_enabled, myip, callsback
from oscar.rendezvous.peer import OscarPeer
from oscar.rendezvous.rendezvous import rendezvous_tlvs
from oscar.OscarUtil import tlv_list
import oscar
import common
import time
import struct
from logging import getLogger
log = getLogger('oscar.directim')
info = log.info
import os.path as os
import wx
from util.BeautifulSoup import BeautifulSoup
from functools import partial
from oscar import OscarException
from common.Protocol import StateMixin
def directconnect(protocol, screenname):
if not isinstance(screenname, str):
raise TypeError('screenname must be a str')
ostrip = lambda s: s.lower().replace(' ', '')
if ostrip(screenname) == ostrip(protocol.self_buddy.name):
raise OscarException('You cannot direct connect with yourself.')
cookie = int(time.time() ** 2)
protocol.rdv_sessions[cookie] = dim = OscarDirectIM(protocol, screenname, cookie)
dim.request()
return dim
class ODCHeader(Packable):
fmt = strlist('\n version 4s # always ODC2\n hdrlen H # length of header\n one H # 1\n six H # 6\n zero H # 0\n cookie Q # sixteen byte rendezvous cookie\n null Q\n length I\n encoding H\n subset H\n flags I\n zero I\n screenname 16s\n null2 16s ')
def make(cls, *a, **k):
k.update(dict(version = 'ODC2', static = 76, one = 1, six = 6, zero = 0, null = 0, null2 = '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'))